package org.ims.inv.service.project.impl;

import java.util.Set;

import org.hibernate.criterion.DetachedCriteria;
import org.ims.inv.dao.project.DAOProjectMaterial;
import org.ims.inv.model.project.ModelProjectMaterial;
import org.ims.inv.service.project.ServiceProjectMaterial;

import cn.trymore.core.exception.DAOException;
import cn.trymore.core.exception.ServiceException;
import cn.trymore.core.service.impl.ServiceGenericImpl;
import cn.trymore.core.util.UtilCollection;

/**
 * Service: 项目材料
 * 
 * @author Jeccy.Zhao
 *
 */
public class ServiceProjectMaterialImpl
extends ServiceGenericImpl<ModelProjectMaterial> implements ServiceProjectMaterial
{

	/**
	 * Repository of project
	 */
	private DAOProjectMaterial daoProjectMaterial;
	
	public ServiceProjectMaterialImpl(DAOProjectMaterial dao)
	{
		super(dao);
		
		this.daoProjectMaterial = dao;
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.ims.inv.service.project.ServiceProjectMaterial#save(java.util.Set)
	 */
	@Override
	public void save(Set<ModelProjectMaterial> materials) throws ServiceException
	{
		try
		{
			if (UtilCollection.isNotEmpty(materials))
			{
				for (ModelProjectMaterial material : materials)
				{
					this.daoProjectMaterial.saveOrUpdate(material);
				}
			}
		}
		catch (DAOException e)
		{
			throw new ServiceException(e);
		}
	}

	/*
	 * (non-Javadoc)
	 * @see cn.trymore.core.service.impl.ServiceGenericImpl#getCriterias(cn.trymore.core.model.ModelBase)
	 */
	@Override
	protected DetachedCriteria getCriterias(ModelProjectMaterial domain)
	{
		DetachedCriteria criteria = DetachedCriteria.forClass(ModelProjectMaterial.class);
		
		return criteria;
	}

	public void setDaoProjectMaterial(DAOProjectMaterial daoProjectMaterial)
	{
		this.daoProjectMaterial = daoProjectMaterial;
	}

	public DAOProjectMaterial getDaoProjectMaterial()
	{
		return daoProjectMaterial;
	}

}
